package com.example.demo.jpa.org;

import com.example.demo.jpa.customer.dto.CustomerDTO;
import com.example.demo.jpa.customer.service.CustomerService;
import com.example.demo.jpa.org.domain.Org;
import com.example.demo.jpa.org.dto.OrgCommand;
import com.example.demo.jpa.org.dto.OrgDto;
import com.example.demo.jpa.org.service.OrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/org")
public class OrgController {
    @Autowired
    OrgService orgService;

    @GetMapping("/{id}")
    public OrgDto getOrgById(@PathVariable Long id) {
        return orgService.findOrgByID(id);
    }

    @PostMapping()
    @ResponseStatus(HttpStatus.CREATED)
    public OrgDto createOrg(@RequestBody OrgCommand orgCommand) {
        return orgService.createOrg(orgCommand);
    }

    @PutMapping("/{id}")
    public OrgDto updateOrg(@PathVariable long id, @RequestBody OrgCommand orgCommand) {
        return orgService.updateOrg(id, orgCommand);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable long id) {
        orgService.deleteById(id);
    }
}

